package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PublishScheduleMaterial 计划素材表
type PublishScheduleMaterial struct {
	ID              string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	MerchantID      string `json:"merchant_id" gorm:"column:merchant_id;primaryKey;type:varchar(30);not null;default:'';index:merchant_id;comment:商户id"`
	ScheduleID      string `json:"schedule_id" gorm:"column:schedule_id;type:int;size:64;comment:计划ID"`
	MaterialID      string `json:"material_id" gorm:"column:material_id;type:int;size:64;comment:素材ID"`
	Duration        int64  `json:"duration" gorm:"column:duration;type:int;size:64;not null;default:0;comment:素材时长[s]"`
	RepeatTimes     int64  `json:"repeat_times" gorm:"column:repeat_times;type:int;size:64;not null;default:1;comment:播放频次"`
	PlayType        int8   `json:"play_type" gorm:"column:play_type;type:tinyint(1);not null;default:1;comment:播放模式,1顺序播放,2定时播放,3错序播放"`
	RegularInterval int64  `json:"regular_interval" gorm:"column:regular_interval;type:int;size:64;not null;default:0;comment:定时间隔"`
	Sort            int8   `json:"sort" gorm:"column:sort;type:tinyint(1);not null;default:0;comment:排序"`
	CreatedAt       int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	UpdatedAt       int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;not null;default:0;index:updated_at;comment:更新时间"`
	DeletedAt       int64  `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;not null;default:0;comment:删除时间"`
}

// TableName 表名
func (PublishScheduleMaterial) TableName() string {
	return "publish_schedule_material"
}

// BeforeCreate 自增id
func (l *PublishScheduleMaterial) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PublishScheduleMaterial{})
}
